from random import *
import pygame
from settings import *

class SmallEnemy(pygame.sprite.Sprite):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load(FILE_PATH + "image/enemy1.png").convert_alpha()
        self.destroy_images = []
        self.destroy_images.extend([
            pygame.image.load(FILE_PATH + "image/enemy1_down1.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy1_down2.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy1_down3.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy1_down4.png").convert_alpha()
        ])
        self.rect = self.image.get_rect()
        self.speed = 2
        self.active = True
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-5 * SCREEN_RECT.height, 0)
        self.mask = pygame.mask.from_surface(self.image)
        self.check()
    def move(self):
        if self.rect.top < SCREEN_RECT.height:
            self.rect.top += self.speed
        else:
            self.reset()
    def reset(self):
        self.active = True
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-5 * SCREEN_RECT.height, 0)
    def check(self):
        if self.rect.right >= SCREEN_RECT.width:
            self.rect.right = SCREEN_RECT.width


class MidEnemy(pygame.sprite.Sprite):

    hp = 8

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load(FILE_PATH + "image/enemy2.png").convert_alpha()
        self.image_hit = pygame.image.load(FILE_PATH + "image/enemy2_hit.png").convert_alpha()
        self.destroy_images = []
        self.destroy_images.extend([
            pygame.image.load(FILE_PATH + "image/enemy2_down1.png").convert_alpha(),
            pygame.image.load(FILE_PATH +"image/enemy2_down2.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy2_down3.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy2_down4.png").convert_alpha()
        ])
        self.rect = self.image.get_rect()
        self.speed = 1
        self.active = True
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-10 * SCREEN_RECT.height, -SCREEN_RECT.height)
        self.mask = pygame.mask.from_surface(self.image)
        self.hit = False
    def move(self):
        if self.rect.top < SCREEN_RECT.height:
            self.rect.top += self.speed
        else:
            self.reset()
    def reset(self):
        self.hp = MidEnemy.hp
        self.active = True
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-10 * SCREEN_RECT.height, -SCREEN_RECT.height)


class BigEnemy(pygame.sprite.Sprite):

    hp = 20

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load(FILE_PATH + "image/enemy3_n1.png").convert_alpha()
        self.image2 = pygame.image.load(FILE_PATH + "image/enemy3_n2.png").convert_alpha()
        self.image_hit = pygame.image.load(FILE_PATH + "image/enemy3_hit.png").convert_alpha()
        self.destroy_images = []
        self.destroy_images.extend([
            pygame.image.load(FILE_PATH + "image/enemy3_down1.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy3_down2.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy3_down3.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy3_down4.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy3_down5.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/enemy3_down6.png").convert_alpha()
        ])
        self.rect = self.image.get_rect()
        self.speed = 1
        self.active = True
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-15 * SCREEN_RECT.height, -5 * SCREEN_RECT.height)
        self.mask = pygame.mask.from_surface(self.image)
        self.hit = False
    def move(self):
        if self.rect.top < SCREEN_RECT.height:
            self.rect.top += self.speed
        else:
            self.reset()
    def reset(self):
        self.active = True
        self.hp = BigEnemy.hp
        self.rect.left = randint(0, SCREEN_RECT.width - self.rect.width)
        self.rect.top = randint(-15 * SCREEN_RECT.height, -5 * SCREEN_RECT.height)
